<template>
	<view class="page">
		<view class="container">
			<view class="d-flex mt-20">
				<view style="width: 150rpx;">
					姓名：
				</view>

				<uni-easyinput v-model="baseFormData.name" placeholder="请输入姓名" />
			</view>
			<view class="d-flex mt-20">
				<view style="width: 150rpx;">
					证件号码：
				</view>

				<uni-easyinput v-model="baseFormData.certificateNumber" placeholder="请输入身份证号" />
			</view>
			<view class="d-flex mt-20">
				<view style="width: 150rpx;">
					性别：
				</view>

				<uni-data-checkbox v-model="baseFormData.gender" :localdata="sexs" />
			</view>

			<view class="d-flex mt-20">
				<view style="width: 150rpx;">
					民族：
				</view>

				<uni-easyinput v-model="baseFormData.nation" placeholder="请输入民族" />
			</view>

			<view class="d-flex mt-20">
				<view style="width: 150rpx;">
					年龄：
				</view>
				<uni-easyinput v-model="baseFormData.age" placeholder="请输入民族" />
			<!-- 	<uni-datetime-picker  style="width: 300rpx;" :clear-icon="false"   :value="baseFormData.birthday" /> -->
			</view>

			<view class="d-flex mt-20">
				<view style="width: 150rpx;">
					地址：
				</view>

				<uni-easyinput v-model="baseFormData.address" placeholder="请输入地址" />
			</view>

			<button class="submit mt-20" type="primary" @click="onSubmit">下一步</button>

			<!-- 失败提示窗 -->
			<uni-popup ref="errorDialog" type="dialog">
				<uni-popup-dialog type="error" cancelText="关闭" confirmText="规则详情" title="提示" content="很遗憾，您不符合公司用人规则"
					@confirm="checkDetail">
				</uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				baseFormData: {
					identityNo: "",
					nationality: "",
					sex: 0,
					birthday: "",
				},
				// 性别
				sexs: [{
					text: '男',
					value: 0
				}, {
					text: '女',
					value: 1
				}],
				personInfo:{}
			}
		},
		onLoad(option) {
			this.baseFormData = JSON.parse(option.personInfo)
			console.log(this.baseFormData);
		},
		methods: {
			checkType(){
				return new Promise( (s,i) => {
					let flag = 0;
					let idCord = this.baseFormData.certificateNumber
					uni.request({
						url: 'http://116.205.142.103:8808/labor/system/user/getCertificateType?certificateNumber='+idCord,
						method: 'get',
						success: res => {
						if(res.data.data > 0){
							flag = 1
							debugger
							uni.showModal({
								content: "身份证号码已存在",
								showCancel: false
							});
						 }
						 if (flag == 0){
						 	uni.navigateTo({
						 		 url: "/pages/addLabor/laborProjectInfo/laborProjectInfo?baseFormData=" + JSON.stringify(this.baseFormData)
						 	 })
						 }
					}
				});
			})
		},
		async onSubmit() {
			let ss = this.baseFormData
			
			if(!ss.name){
				uni.showModal({title: "名称不能为空"})
			}else if(!ss.nation){
				uni.showModal({title: "民族不能为空"})
			}else if(!ss.gender && ss.gender!=0){
				uni.showModal({title: "性别不能为空"})
			}else if(!ss.certificateNumber ){
				uni.showModal({title: "身份证号不能为空"})
			}else if(!ss.age ){
				uni.showModal({title: "年龄不能为空"})
			}else if(!ss.address ){
				uni.showModal({title: "地址不能为空"})
			}else {
				await this.checkType()
			}
		},
		// 不符合条件 查看详情
		checkDetail() {
			console.log("不符合条件 查看详情");
			uni.navigateTo({
				url: "/pages/addLabor/laborRules/laborRules"
			})
		}
	}
}
</script>

<style>
	.page {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 50rpx;
	}

	.d-flex {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}

	.ml-20 {
		margin-left: 20rpx;
	}

	.mt-20 {
		margin-top: 20rpx;
	}

	.container {
		width: 90vw;
	}
</style>
